// 放置 工具方法
const getYearMonthDay = (date) => {
    if(!date){
        date = new Date();
    }
    let year = date.getFullYear();
    let month = date.getMonth();
    let day = date.getDate();
    let week = date.getDay();
    return {
        year,
        month,
        day,
        week
    };
}
const getDate = (year, month, day) => {
    // console.log(new Date(year, month, day))
    return new Date(year, month, day)
}
const getMinSec = (total)=>{
    let result = parseInt(total)
    let m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
    let s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60));
    return {
        m,
        s
    }
}
// 时间戳转换为时间   
// 调用方法传参FormatDate(new Date(Number(time)), 'yyyy-MM-dd hh:mm')
const FormatDate = (date, fmt) => {
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    let o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds()
    };
    for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
            let str = o[k] + '';
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
        }
    };
    function padLeftZero (str) {
        return ('00' + str).substr(str.length);
    } 
    return fmt;
  }

export {
    getYearMonthDay,
    getDate,
    getMinSec,
    FormatDate
}